home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / misc / edu / Calgor.lha / Cal / CalSource / mouse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-21  |  6.2 KB  |  218 lines

  1. /* V1.2 15:02:96 */
  2. /* Mouse.c Project Calgor */
  3.  
  4. #include <hold/extra.h>
  5. #include <exec/types.h>
  6. #include <intuition/intuition.h>
  7. #include <devices/inputevent.h>
  8. #include <stdio.h>
  9. #include <signal.h>
  10. #include <graphics/gfx.h>
  11.  
  12. #include <proto/exec.h>
  13. #include <clib/intuition_protos.h>
  14. #include <clib/console_protos.h>
  15.  
  16. extern void alert(char *);
  17. extern void menu_opt(void);
  18. extern void anim_opt(void);
  19. extern void clean_local(void);
  20.  
  21. extern struct BitMap ft_bitmap;
  22. extern UBYTE *keybufptr;
  23. extern ULONG modeID;
  24. extern UWORD wb_version;
  25.  
  26. void back_drop(void);
  27. void safeclose(struct MsgPort *, struct Window *);
  28. void shutdown(void);
  29. void handler(int);
  30. void clearkeybuf(void);
  31.  
  32. struct Window *my_window = NULL;
  33.  
  34. /* Declare and initialize your NewWindow structure: */
  35. struct NewWindow back_window =
  36. {
  37.   0,            /* LeftEdge    x position of the window. */
  38.   0,            /* TopEdge     y positio of the window. */
  39.   640,           /* Width       640 pixels wide. */
  40.   512,           /* Height      512 lines high. */
  41.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  42.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  43.   IDCMP_MOUSEBUTTONS|IDCMP_ACTIVEWINDOW|IDCMP_INACTIVEWINDOW|IDCMP_RAWKEY,
  44.   WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP|WFLG_BORDERLESS,
  45.   NULL,          /* FirstGadget No Custom Gadgets. */
  46.   NULL,          /* CheckMark   Use Intuition's default CheckMark (v). */
  47.   NULL,          /* Title       Title of the window. */
  48.   NULL,          /* Screen      Connected to the Escreen  */
  49.   NULL,          /* BitMap      No Custom BitMap. */
  50.   0,             /* MinWidth    We do not need to care about these */
  51.   0,             /* MinHeight   since we havent supplied the window with */
  52.   0,             /* MaxWidth    a Sizing Gadget. */
  53.   0,             /* MaxHeight */
  54.   CUSTOMSCREEN   /* Type        Connected to the My custom Screen. */
  55. };
  56.  
  57. struct ExtNewScreen Escreen=
  58. {
  59.   0,            /* LeftEdge  Should always be 0. */
  60.   0,            /* TopEdge   Top of the display.*/
  61.   640,          /* Width  */
  62.   512,          /* Height */
  63.   4,            /* Depth     16 colours. */
  64.   0,            /* DetailPen Text should be drawn with colour reg. 0 */
  65.   1,            /* BlockPen  Blocks should be drawn with colour reg. 1 */
  66.   HIRES|SPRITES,
  67.   CUSTOMSCREEN | NS_EXTENDED, /* Type      Customized screen. */
  68.   NULL,         /* Font      Default font. */
  69.   NULL,         /* Title     The screen' title. */
  70.   NULL,         /* Gadget    Must for the moment be NULL. */
  71.   NULL,         /* BitMap    No special CustomBitMap. */
  72.   NULL          /* TagItems */
  73. };
  74.  
  75. struct InputEvent ievent = { NULL };
  76.  
  77. struct TagItem NSTags[2] =
  78. {
  79.   {SA_DisplayID,NULL},
  80.   {TAG_DONE,NULL}
  81. };
  82.  
  83. struct Screen *my_screen = NULL;
  84.  
  85. SHORT squeek[2];
  86. BOOL lmbpress;
  87. BOOL wactive;
  88. BOOL keypress;
  89.  
  90. void back_drop(void)
  91. {
  92. /* Open Screen  */
  93.  
  94.   NSTags[0].ti_Data = modeID;
  95.   Escreen.Extension = NSTags;
  96.   if(wb_version<37)
  97.     Escreen.ViewModes |= LACE;
  98.   my_screen = (struct Screen *) OpenScreen( (struct NewScreen *) &Escreen );
  99.   if (my_screen==NULL){
  100.      clean_local();
  101.      alert("Failed open screen (back_drop)\n");
  102.   }
  103.   back_window.Screen = my_screen;  /* Window uses my Screen */
  104.   /* Open Window */
  105.   my_window = (struct Window *) OpenWindow( &back_window );
  106.   /* Have we opened the window succesfully? */
  107.   if(my_window == NULL){
  108.     clean_local();
  109.     alert("Failed open window mouse.c (back_drop)\n");
  110.   }
  111.   ClearPointer(my_window);
  112. }
  113.  
  114.  
  115. void safeclose(struct MsgPort *mp, struct Window *win){
  116. struct IntuiMessage *msg=NULL;
  117. struct Node *succ=NULL;;
  118.  
  119.    msg = (struct IntuiMessage *) mp->mp_MsgList.lh_Head;
  120.    while( succ=msg->ExecMessage.mn_Node.ln_Succ ){
  121.      if(msg->IDCMPWindow==win){
  122.        Remove( (struct Node *) msg);
  123.        ReplyMsg((struct Message *) msg);
  124.      }
  125.      msg = (struct IntuiMessage *) succ;
  126.    }
  127. }
  128.  
  129. void shutdown(void){
  130.   if(my_window){
  131.     Forbid();
  132.     safeclose(my_window->UserPort,my_window);
  133.     my_window->UserPort=NULL;
  134.     ModifyIDCMP(my_window,0L);
  135.     Permit();
  136.     CloseWindow(my_window);
  137.     my_window=NULL;
  138.   }
  139.   if(my_screen){
  140.     CloseScreen(my_screen);
  141.     my_screen=NULL;
  142.   }
  143. }
  144.  
  145.  
  146. void handler(int pulse)
  147. {
  148. long actual;
  149. /* SHORT lop; */
  150. ULONG class;
  151. USHORT code;
  152. SHORT mousex, mousey;
  153. struct IntuiMessage *message;
  154.  
  155.       /* Wait (1L << my_window->UserPort->mp_SigBit); */
  156.       keypress = wactive = lmbpress = FALSE;
  157.       squeek[0]=squeek[1]=0;
  158.       actual = 0L;
  159.       while(message = (struct IntuiMessage *)
  160.         GetMsg(my_window->UserPort)){
  161.           class = message->Class;
  162.           code = message->Code;
  163.           mousex = message->MouseX;
  164.           mousey = message->MouseY;
  165.           ievent.ie_position.ie_addr = *((APTR *) message->IAddress);
  166.           ievent.ie_Class = IECLASS_RAWKEY;
  167.           ievent.ie_Code  = message->Code;
  168.           ievent.ie_Qualifier = message->Qualifier;
  169.           ReplyMsg( (struct Message *) message);
  170.           switch(class){
  171.             case(IDCMP_RAWKEY):
  172.               keypress = TRUE;
  173.               actual=RawKeyConvert(&ievent,keybufptr,(KEYBUFF-1),NULL);
  174.               if(actual==-1)
  175.                 clearkeybuf();
  176.               /* Check Key */
  177.               /* for(lop=0;lop<actual;lop++)
  178.                   printf("%X ",*(keybufptr+lop) );
  179.                   printf("\n"); */
  180.               break;
  181.             case(IDCMP_MOUSEBUTTONS):
  182.                switch(code){
  183.                  case SELECTDOWN:
  184.                    squeek[0]=mousex;   /* Squeek 0 x coordinate */
  185.                    squeek[1]=mousey;   /* Squeek 1 y coordinate */
  186.                     lmbpress=TRUE;
  187.                     wactive=TRUE;
  188.                    break;
  189.                  case SELECTUP:
  190.                    break;
  191.                  case MENUDOWN:
  192.                    break;
  193.                  case MENUUP:
  194.                    break;
  195.                  default:
  196.                    clean_local();
  197.                    alert("Unknown code mouse.c (mouse options)\n");
  198.                    break;
  199.                }
  200.             case(IDCMP_ACTIVEWINDOW):
  201.               wactive=TRUE;
  202.               lmbpress=TRUE;
  203.               break;
  204.             case(IDCMP_INACTIVEWINDOW):
  205.               break;
  206.             break;
  207.           }
  208.       }
  209.       signal(SIGINT,handler);
  210. }
  211.  
  212. void clearkeybuf(void){
  213. int loop;
  214.  
  215.     for(loop=0;loop<KEYBUFF;loop++)
  216.       *(keybufptr+loop)= '\0';
  217. }
  218.